function preview(file) {
	var prevDiv = document.getElementById("PreVwImg");
	if (file.files && file.files[0]) {
		var reader = new FileReader();
		reader.onload = function(evt) {
			// prevDiv.innerHTML = '<img class = "ImgCls" src="' +
			// evt.target.result + '" />';
			prevDiv.src = evt.target.result;
		}
		reader.readAsDataURL(file.files[0]);
	} else {
		prevDiv.innerHTML = '<div class="img" src=\'' + file.value
				+ '\'"></div>';
	}

}
function UploadFile() {
	file = document.getElementById("FileInput");
	if (file.files && file.files[0]) {
		var reader = new FileReader();
		var rest = reader.readAsBinaryString(file.files[0]);
		var PicSize = reader.filesize();
		$.ajax({
			url : "http://10.71.200.109:1174",
			type : "POST",
			data : rest,
			headers : {
				"x-ambry-blob-size" : PicSize,
				"Access-Control-Allow-Origin" : "*",
				"X-Auth-Token" : "open-sesame",
				"Content-Type" : "application/octet-stream",
				"x-ambry-service-id" : "CUrlUpload",
				"x-ambry-owner-id" : "111111",
				"x-ambry-content-type" : "image/png",
				"x-ambry-um-description" : "test upload",
			},
			contentType : 'text/html; charset=UTF-8',
			dataType : "json",
			success : function(data) {
				alert(data); // Object
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert(XMLHttpRequest.status);
				alert(XMLHttpRequest.readyState);
				alert(textStatus);
			},
			complete : function(XMLHttpRequest, textStatus) {
				alert("complete!")
			}
		});
	}
}

function GetFile() {
	alert("111111");
	$
			.ajax({
				url : "http://10.71.200.109:1174/AAEAAQAAAAAAAAAAAAAAJGE1MDgxMzJjLWUxOTAtNDA1ZC1iNThhLTE0YzJlNzdiZDUyNw",
				type : "get",
				data : "xxx",
				headers : {
					// "X-Auth-Token" : "open-sesame",
					// "Content-Type" : "application/octet-stream",
					"X-XSS-Protection" : "0"
				},
				dataType : "jsonp",
				jsonp : "callbackParam",
				jsonCallback : "success_jsonpCallback",
				success : function(data) {
					alert("sucess");
					var prevDiv = document.getElementById("PreVwImg");
					prevDiv.src = data.data;
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("error");
					// alert(XMLHttpRequest.status);
					// alert(XMLHttpRequest.readyState);
					// alert(textStatus);
				},
				complete : function(XMLHttpRequest, textStatus) {
					alert("complete!")
				}
			});
}

function UploadFile2BK() {
	file = document.getElementById("FileInput");
	if (file.files && file.files[0]) {
		// document.getElementById("UpLoadForm").submit();
		var formData = new FormData();
	//	var name = document.getElementById("FileInput").val();
		var UserName = UserID;
		
		formData.append("file", file.files[0]);
	//	formData.append("name", name);
		formData.append("UserName", UserName);
		
		$.ajax({
			url : "UpFileServlet/UpLoad",
			type : 'POST',
			data : formData,
			// 告诉jQuery不要去处理发送的数据
			processData : false,
			// 告诉jQuery不要去设置Content-Type请求头
			contentType : false,
			beforeSend : function() {
				console.log("正在进行，请稍候");
			},
			success : function(responseStr) {
				var  obj = JSON.parse(responseStr);
				if (obj.status == "0") {
					alert("上传成功");
					var prevDiv = document.getElementById("PreVwImg");
					prevDiv.src="";
				} else {
					alert("上传失败" + obj.status);
				}
			},
			error : function(responseStr) {
				alert("上传失败 :" + obj.status);
			}
		});
	} else {
		alert("select pic plz!");
	}

}

function GetFile2() {
	var oReq = new XMLHttpRequest();
	oReq
			.open(
					"GET",
					"http://10.71.200.109:1174/AAEAAQAAAAAAAAAAAAAAJGE1MDgxMzJjLWUxOTAtNDA1ZC1iNThhLTE0YzJlNzdiZDUyNw",
					true);
	oReq.responseType = "arraybuffer";
	oReq.onload = function(oEvent) {
		var blob = new Blob([ oReq.response ], {
			type : "image/png"
		});
		var arrayBuffer = oReq.response; // Note: not oReq.responseText
		if (arrayBuffer) {

			var prevDiv = document.getElementById("PreVwImg");
			prevDiv.src = data;
		}
	};
	oReq.send(null);
}